<?php

namespace common\models\customelements;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\customelements\CustomElements;

/**
 * CustomElementsSearch represents the model behind the search form about `common\models\customelements\CustomElements`.
 */
class CustomElementsSearch extends CustomElements
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'set_id', 'required', 'layout', 'imgnum', 'snumber', 'stype', 'sort'], 'integer'],
            [['token', 'name', 'eid', 'title', 'instruct', 'evalue', 'numtype', 'datetype', 'numbertype', 'img', 'imglink', 'alignstyle', 'pictureshow', 'subtitle', 'titlealignstyle'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CustomElements::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'set_id' => $this->set_id,
            'required' => $this->required,
            'layout' => $this->layout,
            'imgnum' => $this->imgnum,
            'snumber' => $this->snumber,
            'stype' => $this->stype,
            'sort' => $this->sort,
        ]);

        $query->andFilterWhere(['like', 'token', $this->token])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'eid', $this->eid])
            ->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'instruct', $this->instruct])
            ->andFilterWhere(['like', 'evalue', $this->evalue])
            ->andFilterWhere(['like', 'numtype', $this->numtype])
            ->andFilterWhere(['like', 'datetype', $this->datetype])
            ->andFilterWhere(['like', 'numbertype', $this->numbertype])
            ->andFilterWhere(['like', 'img', $this->img])
            ->andFilterWhere(['like', 'imglink', $this->imglink])
            ->andFilterWhere(['like', 'alignstyle', $this->alignstyle])
            ->andFilterWhere(['like', 'pictureshow', $this->pictureshow])
            ->andFilterWhere(['like', 'subtitle', $this->subtitle])
            ->andFilterWhere(['like', 'titlealignstyle', $this->titlealignstyle]);

        return $dataProvider;
    }
}
